<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	protected function _initConfig() 
	{
		$baseUrl = $this->getOption("baseUrl");
		Zend_Controller_Front::getInstance()->setBaseUrl($baseUrl);
	}
	
	protected function _initView()
	{
		// Initialize view
		$view = new Zend_View();
		$view->doctype('HTML5'); // HTML 5 doctype
		$view->headTitle('LivePomodoro');
		$view->headLink()->appendStylesheet($view->baseUrl("/css/base.css"));

		//include google web fonts
		$view->headLink()->appendStylesheet("http://fonts.googleapis.com/css?family=Damion|Yellowtail");

		$view->headScript()->appendFile('https://www.google.com/jsapi?key=ABQIAAAA8H-ZwLDIZqsPOMVsVnRASBQPeI8fJhw4p2s793smVG3CnZ7gvBQPnxdaHjvuzgdJ6jloUCPpulsqSw');
		$view->headScript()->appendScript('google.load("jquery", "1.6.2");google.load("jqueryui", "1.8.15");');

		$view->addHelperPath(APPLICATION_PATH.'/views/helpers', 'LivePomodoro_Helper');
        
		// Add it to the ViewRenderer
		$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
		$viewRenderer->setView($view);

		// Return it, so that it can be stored by the bootstrap
		return $view;
	}
	
	protected function _initGoogleAnalytics()
	{
		$ga = $this->getOption("googleanalytics");
		$account = $ga['account'];
		Zend_Registry::set("ga_account", $account);
	}

	protected function _initMultidb()
	{
		if ($this->hasPluginResource("multidb")) {
			$resource = $this->getPluginResource("multidb");
			$resource->init();
			$data_db = $resource->getDb("data_db");
			$auth_db = $resource->getDb("auth_db");
			Zend_Registry::set("data_db", $data_db);
			Zend_Registry::set("auth_db", $auth_db);
		}
	}

	protected function _initLog()
	{
		if ($this->hasPluginResource("log")) {
			$resource = $this->getPluginResource("log");
			$log = $resource->getLog();

			
			$db = Zend_Registry::get("data_db");
				
			$columnMap = array(
				"priority" => "priority",
				"priority_name" => "priorityName",
				"message" => "message"
			);
			$writer = new Zend_Log_Writer_Db($db, "log", $columnMap);
			$log->addWriter($writer);
		
			
			$log->registerErrorHandler();

			Zend_Registry::set("log", $log);
		}
	}

}